/*
 * Copyright 2010 Alessandro Bellucci
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package org.soupframework.gwt.designerpanel.client.event;

import java.util.List;

import com.google.gwt.event.shared.GwtEvent;

public class ObjectSelectionChangedEvent<T> extends GwtEvent<ObjectSelectionChangedEventHandler<T>> {
	/**
	* Event type for object selected events. Represents the meta-data associated with
	* this event.
	*/
	//private final Type<ObjectSelectionChangedEventHandler<T>> TYPE = new Type<ObjectSelectionChangedEventHandler<T>>();

	/**
	* Gets the event type associated with widget selected events.
	* 
	* @return the handler type
	*/
	public static <T> Type<ObjectSelectionChangedEventHandler<T>> getType() {
		return new Type<ObjectSelectionChangedEventHandler<T>>();
	}

	private List<T> selectedObjects;

	public ObjectSelectionChangedEvent(List<T> selectedObjects){
		this.selectedObjects = selectedObjects;
	}

	/**
	 * Returns the number of selected widgets
	 *
	 * @return The number of selected widgets
	 */
	public int getSelectedObjectsCount(){
		return this.selectedObjects != null ? this.selectedObjects.size() : 0;
	}

	/**
	 * Returns selected widgets
	 *
	 * @return selected widgets
	 */
	public Iterable<T> getSelectedWidgets(){
		return this.selectedObjects;
	}

	@Override
	public com.google.gwt.event.shared.GwtEvent.Type<ObjectSelectionChangedEventHandler<T>> getAssociatedType() {
		return getType();
	}

	@Override
	protected void dispatch(ObjectSelectionChangedEventHandler<T> handler) {
		handler.onObjectSelected(this);
	}
}
